<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head>
    <th:block th:include="include :: header('出库作业管理')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="col-sm-12 search-collapse">
        <form id="user-form">
            <div class="select-list">
                <ul>
                    <input type="text" name="inOut" value="2" hidden/>
                    <li>
                        <label>作业状态：</label>
                        <select id="status" name="status" required></select>
                    </li>
                    <li>
                        <label>任务号：</label><input type="text" name="taskNo"/>
                    </li>
                    <li>
                        <label>托盘条码：</label><input type="text" name="trayCode"/>
                    </li>
                    <li>
                        <label>巷道：</label><input type="text" name="roadwayId"/>
                    </li>
                    <li>
                        <label>物资编号：</label><input type="text" name="productId"/>
                    </li>
                    <li>
                        <label>出库单号：</label><input type="text" name="inOrOutId"/>
                    </li>
                    <li>
                        <label>子件条码：</label><input type="text" name="barcodeDetail"/>
                    </li>
                    <li>
                        <label>出库层：</label>
                        <select id="siteId" name="siteId" th:height="300px">
                            <option value="">--请选择--</option>
                            <option value="1">出库一层</option>
                            <option value="2">出库二层</option>
                            <option value="3">出库三层</option>
                            <option value="4">出库四层</option>
                        </select>
                    </li>
                    <li>
                        <label>出库口：</label>
                        <select id="exitId" name="exitId" th:height="300px">
                            <option value="">--请选择--</option>
                            <option value="1">1号提升机</option>
                            <option value="2">2号提升机</option>
                            <option value="3">3号提升机</option>
                            <option value="4">4号提升机</option>
                            <option value="5">5号提升机</option>
                            <option value="6">6号提升机</option>
                        </select>
                    </li>
                    <li>
                        <label>起止时间：</label><input type="text" placeholder="请单击选择开始时间：" name="startTime" id="startTime"/>---
                        <input type="text" placeholder="请单击选择结束时间：" name="finishTime" id="finishTime"/>
                    </li>
                    <li>
                        出入库类型：
                        <select id="inOrOut" required></select>
                    </li>
                    <li>
                        <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                class="fa fa-search"></i>&nbsp;搜索</a>
                        <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                class="fa fa-refresh"></i>&nbsp;重置</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>

    <div class="btn-group-sm" id="toolbar" role="group">
        <a class="btn btn-success" onclick="changeJobpriority(1)" shiro:hasPermission="mydo:mydojob:changeJobpriority">
            <i class="fa fa-caret-down"></i> 提高优先级
        </a>
        <a class="btn btn-success" onclick="changeJobpriority(2)" shiro:hasPermission="mydo:mydojob:changeJobpriority">
            <i class="fa fa-caret-down"></i> 降低优先级
        </a>
    <a class="btn btn-success" onclick="handFinish()" shiro:hasPermission="mydo:mydojob:handFinish">
    <i class="fa fa-plus"></i> 手动完成
    </a>
    <a class="btn btn-danger" onclick="handInvalid()" shiro:hasPermission="mydo:mydojob:handInvalid">
    <i class="fa fa-trash-o"></i> 手动作废
    </a>
    </div>

    <div id="div1" style="height: 350px" class="col-sm-8 select-table table-striped">
        <table id="bootstrap-table" data-mobile-responsive="true"></table>
    </div>
    <div id="div2" style="height: 350px" class="col-sm-8 select-table table-striped">
        <table id="bootstrap-table2" data-mobile-responsive="true"></table>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('mydo:mydojob:edit')}]];
    var removeFlag = [[${@permission.hasPermi('mydo:mydojob:remove')}]];
    var prefix = ctx + "out/mydojob";
    var phaseDatas = [[${@dict.getType('execution_phase')}]];


    layui.use('laydate', function () {
        var laydates = layui.laydate;
        laydates.render({
            elem: '#startTime'
            , type: 'datetime',
            /* ,range: '到' */
            format: 'yyyy-MM-dd HH:mm:ss'
        })
    });

    layui.use('laydate', function () {
        var laydates = layui.laydate;
        laydates.render({
            elem: '#finishTime'
            , type: 'datetime',
            /* ,range: '到' */
            format: 'yyyy-MM-dd HH:mm:ss'
        })
    });


  //子表
    var options2 = {
        updateUrl: ctx + "out/stockindetail/edit/{id}",
        removeUrl: ctx + "out/jobdetail/remove",
        search: false,
        showRefresh: true,
        showColumns: true,
        minimumCountColumns: 2,
        clickToSelect: true,//是否启用点击选中行
        // height: $("#div2").height() / 1,
        sortName: "assignNum",
        sortOrder: "desc",
        modalName: "入库单据子表",
        method: 'post',
        striped: true, //是否显示行间隔色
        pagination: true,//显示分页
        sidePagination: "client",
        pageNumber: 1,
        pageSize: 15,
        pageList: [10, 25],
        columns:
            [{
                checkbox: true,
            },
                {
                    field: 'jobDetailId',
                    title: '子表编号'
                },
                {
                    field: 'jobId',
                    title: '主表编号',
                    sortable: true
                },
                {
                    field: 'inOrOutDId',
                    title: '出库子单',
                    sortable: true
                },
                {
                    field: 'inOrOutId',
                    title: '出库单',
                    sortable: true
                },
                {
                    field: 'lotNo',
                    title: '批号',
                    visible: true
                },
                {
                    field: 'productDetailId',
                    title: '物品子件码',
                    visible: true
                },
                {
                    field: 'productId',
                    title: '物品编号',
                    align: 'center',
                },
                {
                    field: 'productName',
                    title: '物品名称',
                    align: 'center',
                },
                {
                    field: 'outQuantity',
                    title: '数量',
                },
                // {
                //     field: 'giveNum',
                //     title: '回流数量',
                //     align: 'center',
                // },
                // {
                //     field: 'stockinId',
                //     title: '入库单主表编号',
                //     visible: true
                // },
            ],
        onLoadSuccess(data) {
            switch (data.code) {
                case  500:
                    options2.url = "";
                    $('#bootstrap-table2').bootstrapTable("removeAll")
                    $.modal.alertWarning("查询出错！");
                    break;
                default:
                    break;
            }
        },
    };
    //出库作业状态
    $(document).ready(function () {
        $.post("/bas/basType/list",{parentId:'02'},function(data){

            $("#status").append("<option value="+data.rows[0].typeValue+" selected >"+data.rows[0].typeName+"</option>");
            // alert(data.rows[0].inOrOut);
            for(var i=1;i<data.total;i++){
                $("#status").append("<option value="+data.rows[i].typeValue+">"+data.rows[i].typeName+"</option>");
            }
        });
    });
    //出库作业类型
    $(document).ready(function () {
        $.post("/bas/inoroutType/list",{inOrOutTypeId:2},function(data){

            $("#inOrOut").append("<option value=''>----请选择----</option>");
            // alert(data.rows[0].inOrOut);
            for(var i=0;i<data.total;i++){
                $("#inOrOut").append("<option value="+data.rows[i].inOrOut+">"+data.rows[i].inOrOutTypeName+"</option>");
            }
        });
    });
    $('#bootstrap-table2').bootstrapTable(options2)
    //主表
    var options = {
        url: prefix+"/list",
        detailView: false,//父子表
        search: false,
        showRefresh: true,
        singleSelect:true,
        showColumns: true,
        height: $("#div1").height() / 1,
        minimumCountColumns: 2,
        clickToSelect: true,//是否启用点击选中行
        createUrl: prefix + "/add",
        updateUrl: prefix + "/edit/{id}",
        removeUrl: prefix + "/remove",
        handFinishUrl: prefix + "/handFinish",
        handInvalidUrl: prefix + "/handInvalid",
        changeJobStatusUrl: prefix + "/changeJobStatus",
        changeJobpriorityUrl: prefix + "/changeJobpriority",
        sortName: "createTime",
        sortOrder: "desc",
        modalName: "出库作业信息",
        columns: [{
            checkbox: true
        },
            {
                field: 'jobId',
                title: '作业id'
            },
            {
                field: 'status',
                title: '作业状态',
                formatter: function (value, row, index) {
                    if (value == 1) {
                        return "未执行";
                    } else if (value == 0) {
                        return "待执行";
                    } else if (value == 3) {
                        return "正执行";
                    } else if (value == 4) {
                        return "已完成";
                    }else if (value == 5) {
                        return "已作废";
                    }

                }
            },

            {
                field: 'taskNo',
                title: '任务号'
            },
            // {
            //     field: 'supplierName',
            //     title: '供应商'
            // },

            {
                field: 'trayCode',
                title: '托盘码'
            },
            {
                field: 'roadwayId',
                title: '巷道'
            },
            {
                field: 'cargoSpaceId',
                title: '货位'
            },
            // {
            //     field: 'targetRoadwayId',
            //     title: '目标巷道'
            // },
            // {
            //     field: 'targetCargoSpaceId',
            //     title: '目标货位'
            // },

            // {
            //     field: 'workshopName',
            //     title: '车间'
            // },
            {
                field: 'priority',
                title: '优先级'
            },
            {
                field: 'executionPhase',
                title: '执行阶段',
                formatter: function(value, row, index) {
                    return $.table.selectDictLabel(phaseDatas, value);
                }
            },
            {
                field: 'inOrOut',
                title: '出库类型',
                formatter: function (value, row, index) {
                    if (value == 10) {
                        return "整托出库";
                    } else if (value == 11) {
                        return "拣选出库";
                    } else if (value == 12) {
                        return "空托盘出库";
                    } else if (value == 14) {
                        return "盘点出库";
                    } else if (value == 20) {
                        return "移库";
                    }

                }
            },
            {
                field: 'createTime',
                title: '创建时间',
                sortable: true,
            },
            {
                field: 'startTime',
                title: '开始时间'
            },
            {
                field: 'finishTime',
                title: '完成时间'
            },

            {
                field: 'exitId',
                title: '出口'
            },
            {
                field: 'siteId',
                title: '出库层'
            },
            {
                field: 'outId',
                title: '装车顺序'
            }
        ],
        //双击显示主表
        onClickRow: function (t, e) {
            options2.url = ctx + "mydo/jobdetail/list?jobId=" + t.jobId;
            $('#bootstrap-table2').bootstrapTable("refresh", options2)
        }
    };
    $.table.init(options);


    function handFinish() {
        var checkedItems = $('#bootstrap-table').bootstrapTable('getSelections');
        if(checkedItems[0].status!=3){
            alert("只能完成正在执行的作业");
            return;
        }
        $.post("/out/mydojob/handFinish", {
            jobId: checkedItems[0].jobId
        }, function (result) {
            alert(result.msg);
            //window.location.reload();
        })
    }


    function handInvalid() {
        var checkedItems = $('#bootstrap-table').bootstrapTable('getSelections');
        console.log(checkedItems[0].status != 1)
        if(checkedItems[0].status != 1){
            alert("只能作废未执行的作业");
            return;
        }
        $.post("/out/mydojob/handInvalid", {
            jobId: checkedItems[0].jobId
        }, function (result) {
           alert(result.msg);
        })
    }


    function changeJobpriority(a) {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录！");
            return;
        }
        // if (rows.length > 1) {
        //     $.modal.alertWarning("只允许选择一条记录！");
        //     return;
        // }
        $.modal.confirm("确认要更改选中的" + rows.length + "条作业优先级吗?", function () {
            var url = table.options.changeJobpriorityUrl;
            var data = {"ids": rows.join(), "pro": a};
            $.operate.submit(url, "post", "json", data);
        });
    }
</script>
</body>
</html>